package com.dawnling.androidutils.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.dawnling.androidutils.R;
import com.dawnling.androidutils.ui.MainActivity;
import com.jph.takephoto.model.TImage;

import java.io.ByteArrayOutputStream;
import java.io.File;

/**
 */
public class MyPhotoAdater extends BaseQuickAdapter<String, BaseViewHolder> {

    public Listener mListener = null;
    private Context context;

    public MyPhotoAdater(Context context) {
        super(R.layout.item_photo);
        this.context = context;
    }

    @Override
    protected void convert(final BaseViewHolder helper, String item) {
        ImageView imgDelete = helper.getView(R.id.imgDelete);
        ImageView imgPhoto = helper.getView(R.id.imgPhoto);

        if (!"".equals(item)){
            //有拍照返回图 glide防止OOM
            Glide.with(context).load(new File(item)).into(imgPhoto);
            imgDelete.setVisibility(View.VISIBLE);
        }else {
            imgPhoto.setImageResource(R.mipmap.btn_add);
            imgDelete.setVisibility(View.INVISIBLE);
        }

        imgDelete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mListener.deleteClick(helper.getAdapterPosition());
            }
        });
    }

    public interface Listener{
        //删除照片
        public void deleteClick(int position);
    }
}
